import mongoose from 'mongoose'
const Schema=mongoose.Schema

const {ObjectId}=Schema.Types
const  movieSchema=new Schema({
  translatedTitle:String,//译名
  title:String,//片名
  age:Number,//年代
  place:String,//产地
  classification:String,//类别
  language:Array,//语言 
  releaseDate:String,//上映日期
  doubanGrade:String,//豆瓣评分
  lengthOf:Number,//片长
  direct:String,//导演
  summary:String,//简介
  cover:String,//封面
  poster:String,//简介图
  baidudyun:String,//百度云地址
  posterKey: String,//七牛云
  coverKey: String,//七牛云
  meta:{
      createdAt:{
          type:Date,
          default:Date.now
      },
      updatedAt:{
          type:Date,
          default:Date.now()
      }
  }
})

movieSchema.pre('save',function(next){
    if(this.isNew){
        this.meta.createdAt=this.meta.updatedAt=Date.now()
    }else{
        this.meta.updatedAt=Date.now()
    }
    next()
})
mongoose.model('Movie',movieSchema)